import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';

import 'MyPagedListView.dart';

class PageableQueryFrontLayer<PageKeyType, ItemType> extends HookWidget {
  final int total;
  final PagingController<PageKeyType, ItemType> pagingController;
  final Function(BuildContext context, ItemType item, int index) itemBuilder;
  final String? resource;

  const PageableQueryFrontLayer({
    Key? key,
    this.total = 0,
    required this.pagingController,
    required this.itemBuilder,
    this.resource,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.only(left: 16, top: 12, bottom: 12),
          child: RichText(
            text: TextSpan(
              style: Theme.of(context).textTheme.bodySmall,
              children: [
                const TextSpan(text: "共"),
                TextSpan(
                  text: total.toString(),
                  style: Theme.of(context).textTheme.bodySmall?.copyWith(
                      color: Theme.of(context).colorScheme.secondary),
                ),
                const TextSpan(text: "个结果"),
              ],
            ),
          ),
        ),
        Expanded(
          child: MyPagedListView(
            pagingController: pagingController,
            itemBuilder: (BuildContext context, ItemType item, int index) {
              return itemBuilder(context, item, index);
            },
          ),
        ),
      ],
    );
  }
}
